package Boke;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface IntegerStack<Integer>{
	public Integer push(Integer item);
	public Integer pop();
	public Integer peek(); 
	public boolean empty(); 
	public int size(); 
}
class ArrayListIntegerStack implements IntegerStack<Integer>{
	private List<Integer> list;
	
	public ArrayListIntegerStack(){
		list = new ArrayList<Integer>();
	}


	

	@Override
	public Integer push(Integer item) {
		// TODO Auto-generated method stub
		if(item==null)
			return null;
		list.add(item);
		return item;
	}


	@Override
	public Integer pop() {
		// TODO Auto-generated method stub
		if(list.isEmpty())
			return null;
		return list.remove(list.size()-1);
	}


	@Override
	public Integer peek() {
		// TODO Auto-generated method stub
		if(list.isEmpty())
			return null;
		return list.get(list.size()-1);
	}


	@Override
	public boolean empty() {
		// TODO Auto-generated method stub
		return list.isEmpty();
	}


	@Override
	public int size() {
		// TODO Auto-generated method stub
		return list.size();
	}
	
	@Override
	public String toString() {
		return list.toString();
	}

	
}
public class Main3 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayListIntegerStack stack = new ArrayListIntegerStack();
		Scanner in = new Scanner (System.in);
		int m = in.nextInt();
		
		for (int i = 0; i < m; i++) {
			stack.push(in.nextInt());
			System.out.println(stack.peek());
			
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
		int x= in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
			
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
	}

}
